#include "comm/my_thread_mem.h"

// golbal object, for asan check
static my_thread_mem_freelists_t            *mem_freelists;
static my_thread_4kaligned_mem_freelists_t  *aligned_mem_freelists;


int main()
{
    char buf[4096] = { 0 };

    my_mem_init(1);
    my_4kaligned_mem_init(1);

    mem_freelists = my_thread_mem_freelists_create(1);
    aligned_mem_freelists = my_thread_4kaligned_mem_freelists_create(1);

    void *p01 = my_thread_mem_freelists_alloc(mem_freelists, 4);
#if (MY_MEM_NO_POOL)
    bzero(p01, 4);
#else
    bzero(p01, 64);
#endif
    void *p02 = my_thread_mem_freelists_alloc(mem_freelists, 8);
#if (MY_MEM_NO_POOL)
    bzero(p02, 8);
#else
    bzero(p02, 64);
#endif
    void *p03 = my_thread_mem_freelists_alloc(mem_freelists, 16);
#if (MY_MEM_NO_POOL)
    bzero(p03, 16);
#else
    bzero(p03, 64);
#endif
    void *p04 = my_thread_mem_freelists_alloc(mem_freelists, 20);
#if (MY_MEM_NO_POOL)
    bzero(p04, 20);
#else
    bzero(p04, 64);
#endif
    void *p05 = my_thread_mem_freelists_alloc(mem_freelists, 64);
    bzero(p05, 64);
    void *p06 = my_thread_mem_freelists_alloc(mem_freelists, 127);
#if (MY_MEM_NO_POOL)
    bzero(p06, 127);
#else
    bzero(p06, 128);
#endif
    void *p07 = my_thread_mem_freelists_alloc(mem_freelists, 128);
    bzero(p07, 128);
    void *p08 = my_thread_mem_freelists_alloc(mem_freelists, 255);
#if (MY_MEM_NO_POOL)
    bzero(p08, 255);
#else
    bzero(p08, 256);
#endif
    void *p09 = my_thread_mem_freelists_alloc(mem_freelists, 510);
#if (MY_MEM_NO_POOL)
    bzero(p09, 510);
#else
    bzero(p09, 512);
#endif
    void *p10 = my_thread_mem_freelists_alloc(mem_freelists, 512);
    bzero(p10, 512);
    void *p11 = my_thread_mem_freelists_alloc(mem_freelists, 513);
#if (MY_MEM_NO_POOL)
    bzero(p11, 513);
#else
    bzero(p11, 1024);
#endif
    void *p12 = my_thread_mem_freelists_alloc(mem_freelists, 1024);
    bzero(p12, 1024);
    void *p13 = my_thread_mem_freelists_alloc(mem_freelists, 1025);
#if (MY_MEM_NO_POOL)
    bzero(p13, 1025);
#else
    bzero(p13, 2048);
#endif
    void *p14 = my_thread_mem_freelists_alloc(mem_freelists, 2048);
    bzero(p14, 2048);
    void *p15 = my_thread_mem_freelists_alloc(mem_freelists, 4096);
    bzero(p15, 4096);
    void *p16 = my_thread_mem_freelists_alloc(mem_freelists, 4097);
#if (MY_MEM_NO_POOL)
    bzero(p16, 4097);
#else
    bzero(p16, 8192);
#endif
    void *p17 = my_thread_mem_freelists_alloc(mem_freelists, 8192);
    bzero(p17, 8192);
    void *p18 = my_thread_mem_freelists_alloc(mem_freelists, 8193);
#if (MY_MEM_NO_POOL)
    bzero(p18, 8193);
#else
    bzero(p18, 16384);
#endif
    void *p19 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 14);
    bzero(p19, 1 << 14);
    void *p20 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 15);
    bzero(p20, 1 << 15);
    void *p21 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 16);
    bzero(p21, 1 << 16);
    void *p22 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 17);
    bzero(p22, 1 << 17);
    void *p23 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 18);
    bzero(p23, 1 << 18);
    void *p24 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 19);
    bzero(p24, 1 << 19);
    void *p25 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 20);
    bzero(p25, 1 << 20);
    void *p26 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 21);
    bzero(p26, 1 << 21);
    void *p27 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 22);
    bzero(p27, 1 << 22);
    void *p28 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 23);
    bzero(p28, 1 << 23);
    void *p29 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 24);
    bzero(p29, 1 << 24);


    void *a01 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, 1);
    assert((intptr_t)a01 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a01, (1));
#else
    bzero(a01, (1 << 12));
#endif
    void *a02 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 12));
    assert((intptr_t)a02 % MY_PAGE_SIZE == 0);
    bzero(a02, (1 << 12));
    void *a03 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 12) + 1);
    assert((intptr_t)a03 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a03, (1 << 12) + 1);
#else
    bzero(a03, (1 << 13));
#endif
    void *a04 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 13));
    assert((intptr_t)a04 % MY_PAGE_SIZE == 0);
    bzero(a04, (1 << 13));
    void *a05 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 13) + 1);
    assert((intptr_t)a05 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a05, (1 << 13) + 1);
#else
    bzero(a05, (1 << 14));
#endif
    void *a06 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 14));
    assert((intptr_t)a06 % MY_PAGE_SIZE == 0);
    bzero(a06, (1 << 14));
    void *a07 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 14) + 1);
    assert((intptr_t)a07 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a07, (1 << 14) + 1);
#else
    bzero(a07, (1 << 15));
#endif
    void *a08 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 15));
    assert((intptr_t)a08 % MY_PAGE_SIZE == 0);
    bzero(a08, (1 << 15));
    void *a09 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 15) + 1);
    assert((intptr_t)a09 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a09, (1 << 15) + 1);
#else
    bzero(a09, (1 << 16));
#endif
    void *a10 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 16));
    assert((intptr_t)a10 % MY_PAGE_SIZE == 0);
    bzero(a10, (1 << 16));
    void *a11 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 16) + 1);
    assert((intptr_t)a11 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a11, (1 << 16) + 1);
#else
    bzero(a11, (1 << 17));
#endif
    void *a12 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 17));
    assert((intptr_t)a12 % MY_PAGE_SIZE == 0);
    bzero(a12, (1 << 17));
    void *a13 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 17) + 1);
    assert((intptr_t)a13 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a13, (1 << 17) + 1);
#else
    bzero(a13, (1 << 18));
#endif
    void *a14 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 18));
    assert((intptr_t)a14 % MY_PAGE_SIZE == 0);
    bzero(a14, (1 << 18));
    void *a15 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 18) + 1);
    assert((intptr_t)a15 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a15, (1 << 18) + 1);
#else
    bzero(a15, (1 << 19));
#endif
    void *a16 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 19));
    assert((intptr_t)a16 % MY_PAGE_SIZE == 0);
    bzero(a16, (1 << 19));
    void *a17 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 19) + 1);
    assert((intptr_t)a17 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a17, (1 << 19) + 1);
#else
    bzero(a17, (1 << 20));
#endif
    void *a18 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 20) + 1);
    assert((intptr_t)a18 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a18, (1 << 20) + 1);
#else
    bzero(a18, (1 << 21));
#endif
    void *a19 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 21) + 1);
    assert((intptr_t)a19 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a19, (1 << 21) + 1);
#else
    bzero(a19, (1 << 22));
#endif
    void *a20 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 22) + 1);
    assert((intptr_t)a20 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a20, (1 << 22) + 1);
#else
    bzero(a20, (1 << 23));
#endif
    void *a21 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 23) + 1);
    assert((intptr_t)a21 % MY_PAGE_SIZE == 0);
    bzero(a21, (1 << 23) + 1);
    
    printf("======================\n");
    my_mem_status_report(buf, 4096);
    printf(buf);
    my_4kaligned_mem_status_report(buf, 4096);
    printf(buf);


    my_thread_mem_freelists_free(mem_freelists, p01);
    my_thread_mem_freelists_free(mem_freelists, p02);
    my_thread_mem_freelists_free(mem_freelists, p03);
    my_thread_mem_freelists_free(mem_freelists, p04);
    my_thread_mem_freelists_free(mem_freelists, p05);
    my_thread_mem_freelists_free(mem_freelists, p06);
    my_thread_mem_freelists_free(mem_freelists, p07);
    my_thread_mem_freelists_free(mem_freelists, p08);
    my_thread_mem_freelists_free(mem_freelists, p09);
    my_thread_mem_freelists_free(mem_freelists, p10);
    my_thread_mem_freelists_free(mem_freelists, p11);
    my_thread_mem_freelists_free(mem_freelists, p12);
    my_thread_mem_freelists_free(mem_freelists, p13);
    my_thread_mem_freelists_free(mem_freelists, p14);
    my_thread_mem_freelists_free(mem_freelists, p15);
    my_thread_mem_freelists_free(mem_freelists, p16);
    my_thread_mem_freelists_free(mem_freelists, p17);
    my_thread_mem_freelists_free(mem_freelists, p18);
    my_thread_mem_freelists_free(mem_freelists, p19);
    my_thread_mem_freelists_free(mem_freelists, p20);
    my_thread_mem_freelists_free(mem_freelists, p21);
    my_thread_mem_freelists_free(mem_freelists, p22);
    my_thread_mem_freelists_free(mem_freelists, p23);
    my_thread_mem_freelists_free(mem_freelists, p24);
    my_thread_mem_freelists_free(mem_freelists, p25);
    my_thread_mem_freelists_free(mem_freelists, p26);
    my_thread_mem_freelists_free(mem_freelists, p27);
    my_thread_mem_freelists_free(mem_freelists, p28);
    my_thread_mem_freelists_free(mem_freelists, p29);

    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a01);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a02);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a03);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a04);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a05);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a06);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a07);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a08);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a09);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a10);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a11);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a12);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a13);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a14);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a15);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a16);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a17);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a18);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a19);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a20);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a21);

    printf("======================\n");
    my_mem_status_report(buf, 4096);
    printf(buf);
    my_4kaligned_mem_status_report(buf, 4096);
    printf(buf);

    p01 = my_thread_mem_freelists_alloc(mem_freelists, 4);
#if (MY_MEM_NO_POOL)
    bzero(p01, 4);
#else
    bzero(p01, 64);
#endif
    p02 = my_thread_mem_freelists_alloc(mem_freelists, 8);
#if (MY_MEM_NO_POOL)
    bzero(p02, 8);
#else
    bzero(p02, 64);
#endif
    p03 = my_thread_mem_freelists_alloc(mem_freelists, 16);
#if (MY_MEM_NO_POOL)
    bzero(p03, 16);
#else
    bzero(p03, 64);
#endif
    p04 = my_thread_mem_freelists_alloc(mem_freelists, 20);
#if (MY_MEM_NO_POOL)
    bzero(p04, 20);
#else
    bzero(p04, 64);
#endif
    p05 = my_thread_mem_freelists_alloc(mem_freelists, 64);
    bzero(p05, 64);
    p06 = my_thread_mem_freelists_alloc(mem_freelists, 127);
#if (MY_MEM_NO_POOL)
    bzero(p06, 127);
#else
    bzero(p06, 128);
#endif
    p07 = my_thread_mem_freelists_alloc(mem_freelists, 128);
    bzero(p07, 128);
    p08 = my_thread_mem_freelists_alloc(mem_freelists, 255);
#if (MY_MEM_NO_POOL)
    bzero(p08, 255);
#else
    bzero(p08, 256);
#endif
    p09 = my_thread_mem_freelists_alloc(mem_freelists, 510);
#if (MY_MEM_NO_POOL)
    bzero(p09, 510);
#else
    bzero(p09, 512);
#endif
    p10 = my_thread_mem_freelists_alloc(mem_freelists, 512);
    bzero(p10, 512);
    p11 = my_thread_mem_freelists_alloc(mem_freelists, 513);
#if (MY_MEM_NO_POOL)
    bzero(p11, 513);
#else
    bzero(p11, 1024);
#endif
    p12 = my_thread_mem_freelists_alloc(mem_freelists, 1024);
    bzero(p12, 1024);
    p13 = my_thread_mem_freelists_alloc(mem_freelists, 1025);
#if (MY_MEM_NO_POOL)
    bzero(p13, 1025);
#else
    bzero(p13, 2048);
#endif
    p14 = my_thread_mem_freelists_alloc(mem_freelists, 2048);
    bzero(p14, 2048);
    p15 = my_thread_mem_freelists_alloc(mem_freelists, 4096);
    bzero(p15, 4096);
    p16 = my_thread_mem_freelists_alloc(mem_freelists, 4097);
#if (MY_MEM_NO_POOL)
    bzero(p16, 4097);
#else
    bzero(p16, 8192);
#endif
    p17 = my_thread_mem_freelists_alloc(mem_freelists, 8192);
    bzero(p17, 8192);
    p18 = my_thread_mem_freelists_alloc(mem_freelists, 8193);
#if (MY_MEM_NO_POOL)
    bzero(p18, 8193);
#else
    bzero(p18, 16384);
#endif
    p19 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 14);
    bzero(p19, 1 << 14);
    p20 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 15);
    bzero(p20, 1 << 15);
    p21 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 16);
    bzero(p21, 1 << 16);
    p22 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 17);
    bzero(p22, 1 << 17);
    p23 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 18);
    bzero(p23, 1 << 18);
    p24 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 19);
    bzero(p24, 1 << 19);
    p25 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 20);
    bzero(p25, 1 << 20);
    p26 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 21);
    bzero(p26, 1 << 21);
    p27 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 22);
    bzero(p27, 1 << 22);
    p28 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 23);
    bzero(p28, 1 << 23);
    p29 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 24);
    bzero(p29, 1 << 24);


    // heap-buffer-overflow test
/*
    char p30 = *((char *)p29 + (1 << 24));
    (void)p30;
*/


    a01 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, 1);
    assert((intptr_t)a01 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a01, 1);
#else
    bzero(a01, (1 << 12));
#endif
    a02 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 12));
    assert((intptr_t)a02 % MY_PAGE_SIZE == 0);
    bzero(a02, (1 << 12));
    a03 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 12) + 1);
    assert((intptr_t)a03 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a03, (1 << 12) + 1);
#else
    bzero(a03, (1 << 13));
#endif
    a04 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 13));
    assert((intptr_t)a04 % MY_PAGE_SIZE == 0);
    bzero(a04, (1 << 13));
    a05 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 13) + 1);
    assert((intptr_t)a05 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a05, (1 << 13) + 1);
#else
    bzero(a05, (1 << 14));
#endif
    a06 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 14));
    assert((intptr_t)a06 % MY_PAGE_SIZE == 0);
    bzero(a06, (1 << 14));
    a07 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 14) + 1);
    assert((intptr_t)a07 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a07, (1 << 14) + 1);
#else
    bzero(a07, (1 << 15));
#endif
    a08 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 15));
    assert((intptr_t)a08 % MY_PAGE_SIZE == 0);
    bzero(a08, (1 << 15));
    a09 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 15) + 1);
    assert((intptr_t)a09 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a09, (1 << 15) + 1);
#else
    bzero(a09, (1 << 16));
#endif
    a10 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 16));
    assert((intptr_t)a10 % MY_PAGE_SIZE == 0);
    bzero(a10, (1 << 16));
    a11 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 16) + 1);
    assert((intptr_t)a11 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a11, (1 << 16) + 1);
#else
    bzero(a11, (1 << 17));
#endif
    a12 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 17));
    assert((intptr_t)a12 % MY_PAGE_SIZE == 0);
    bzero(a12, (1 << 17));
    a13 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 17) + 1);
    assert((intptr_t)a13 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a13, (1 << 17) + 1);
#else
    bzero(a13, (1 << 18));
#endif
    a14 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 18));
    assert((intptr_t)a14 % MY_PAGE_SIZE == 0);
    bzero(a14, (1 << 18));
    a15 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 18) + 1);
    assert((intptr_t)a15 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a15, (1 << 18) + 1);
#else
    bzero(a15, (1 << 19));
#endif
    a16 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 19));
    assert((intptr_t)a16 % MY_PAGE_SIZE == 0);
    bzero(a16, (1 << 19));
    a17 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 19) + 1);
    assert((intptr_t)a17 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a17, (1 << 19) + 1);
#else
    bzero(a17, (1 << 20));
#endif
    a18 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 20) + 1);
    assert((intptr_t)a18 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a18, (1 << 20) + 1);
#else
    bzero(a18, (1 << 21));
#endif
    a19 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 21) + 1);
    assert((intptr_t)a19 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a19, (1 << 21) + 1);
#else
    bzero(a19, (1 << 22));
#endif
    a20 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 22) + 1);
    assert((intptr_t)a20 % MY_PAGE_SIZE == 0);
#if (MY_MEM_NO_POOL)
    bzero(a20, (1 << 22) + 1);
#else
    bzero(a20, (1 << 23));
#endif
    a21 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, (1 << 23) + 1);
    assert((intptr_t)a21 % MY_PAGE_SIZE == 0);
    bzero(a21, (1 << 23) + 1);

    printf("======================\n");
    my_mem_status_report(buf, 4096);
    printf(buf);
    my_4kaligned_mem_status_report(buf, 4096);
    printf(buf);

    my_thread_mem_freelists_free(mem_freelists, p01);
    my_thread_mem_freelists_free(mem_freelists, p02);
    my_thread_mem_freelists_free(mem_freelists, p03);
    my_thread_mem_freelists_free(mem_freelists, p04);
    my_thread_mem_freelists_free(mem_freelists, p05);
    my_thread_mem_freelists_free(mem_freelists, p06);
    my_thread_mem_freelists_free(mem_freelists, p07);
    my_thread_mem_freelists_free(mem_freelists, p08);
    my_thread_mem_freelists_free(mem_freelists, p09);
    my_thread_mem_freelists_free(mem_freelists, p10);
    my_thread_mem_freelists_free(mem_freelists, p11);
    my_thread_mem_freelists_free(mem_freelists, p12);
    my_thread_mem_freelists_free(mem_freelists, p13);
    my_thread_mem_freelists_free(mem_freelists, p14);
    my_thread_mem_freelists_free(mem_freelists, p15);
    my_thread_mem_freelists_free(mem_freelists, p16);
    my_thread_mem_freelists_free(mem_freelists, p17);
    my_thread_mem_freelists_free(mem_freelists, p18);
    my_thread_mem_freelists_free(mem_freelists, p19);
    my_thread_mem_freelists_free(mem_freelists, p20);
    my_thread_mem_freelists_free(mem_freelists, p21);
    my_thread_mem_freelists_free(mem_freelists, p22);
    my_thread_mem_freelists_free(mem_freelists, p23);
    my_thread_mem_freelists_free(mem_freelists, p24);
    my_thread_mem_freelists_free(mem_freelists, p25);
    my_thread_mem_freelists_free(mem_freelists, p26);
    my_thread_mem_freelists_free(mem_freelists, p27);
    my_thread_mem_freelists_free(mem_freelists, p28);
    my_thread_mem_freelists_free(mem_freelists, p29);

    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a01);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a02);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a03);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a04);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a05);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a06);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a07);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a08);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a09);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a10);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a11);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a12);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a13);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a14);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a15);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a16);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a17);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a18);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a19);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a20);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, a21);

    void *o01 = my_thread_mem_freelists_alloc(mem_freelists, 1 << 25);
    my_thread_mem_freelists_free(mem_freelists, o01);
    void *o02 = my_thread_4kaligned_mem_freelists_alloc(aligned_mem_freelists, 1 << 25);
    my_thread_4kaligned_mem_freelists_free(aligned_mem_freelists, o02);

    printf("======================\n");
    my_mem_status_report(buf, 4096);
    printf(buf);
    my_4kaligned_mem_status_report(buf, 4096);
    printf(buf);

    my_thread_mem_freelists_destroy(mem_freelists);
    my_thread_4kaligned_mem_freelists_destroy(aligned_mem_freelists);

    printf("======================\n");
    my_mem_status_report(buf, 4096);
    printf(buf);
    my_4kaligned_mem_status_report(buf, 4096);
    printf(buf);

    my_mem_clean();
    my_4kaligned_mem_clean();

    printf("======================\n");
    my_mem_status_report(buf, 4096);
    printf(buf);
    my_4kaligned_mem_status_report(buf, 4096);
    printf(buf);
}
